<?php


namespace app\site\controller\auth;



use app\common\exception\MiException;
use app\model\site\SiteUserGroup;
use app\Request;
use app\site\controller\AController;
use app\site\controller\traits\CurdTrait;
use app\site\service\auth\AdminRuleService;
use app\site\service\site\SiteUserGroupService;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;


class SiteUserGroupController extends AController {



    public function options(): \think\response\Json
    {
        $options = SiteUserGroupService::instance()->setField("id,title")->setStatus(1)->select();
        return jsonSuccess([
            'options' => $options,
        ]);
    }

    /**
     * @throws DbException
     */
    public function index(){
        return $this->reqSer->setService(SiteUserGroupService::instance())->setPaginate()->getResponse();
    }

    /**
     * @throws MiException
     */
    public function add(){
        return $this->reqSer->setService(SiteUserGroupService::instance())->add()->getResponse();
    }

    /**
     * @throws DataNotFoundException
     * @throws ModelNotFoundException
     * @throws DbException
     * @throws MiException
     */
    public function edit(Request $request){
        if($request->isPost()){
            return $this->reqSer->setService(SiteUserGroupService::instance())->edit()->getResponse();
        }else{
            return $this->reqSer->setService(SiteUserGroupService::instance())->setFind()->getResponse();
        }
    }

    /**
     * @throws DataNotFoundException
     * @throws ModelNotFoundException
     * @throws DbException
     * @throws MiException
     */
    public function del(){
        return $this->reqSer->setService(SiteUserGroupService::instance())->delete()->getResponse();
    }

}
